package jwdt.web.action;

import jwdt.xadmin.info.bean.TNews;
import jwdt.xadmin.info.bean.TType;

import com.ezerg.db.Jdb;
import com.ezerg.db.ext.PageUtil;
import com.ezerg.web.Form;
import com.ezerg.web.Module;
import com.ezerg.web.Page;

public class ListAction extends BaseAction {
	
	public Page execute(Form f, Module m) throws Exception{
		//
		int page = f.getInt("page", 1);
		int pageSize = f.getInt("pageSize", 20);
		int typeid = f.getInt("id",0,true);
		TType type = (TType)Jdb.get().get(TType.class, typeid);
		if(type==null) {
			f.add("ret", "您选择的栏目不存在");
			return m.findPage("tips");
		}
		f.add("type", type);
		//相关
		f.add("about", Jdb.get().query(super.select_news+" where checked=1 and typeid in(select id from t_type where fid= " + typeid + ") or typeid= "+ typeid + super.order_news+" limit 8"));
		//滚动图片
		f.add("imgs", Jdb.get().query(super.select_news+" where goodnews=1 and checked=1 and picnews=1 "+super.order_news+" limit 5"));
		//最新
		f.add("qzzx", Jdb.get().query(super.select_news+" where checked=1 "+super.order_news+" limit 8"));
		//
		String where = " where checked=1 ";
		int rows = 4;
		if(type.getChildren().size()>0) {
			super.getListByTypeFid(typeid, "objs", rows, f);//
			super.getListByTypeFid2(typeid, 0, "objs0", rows, f);//
			super.getListByTypeFid2(typeid, 1, "objs1", rows, f);//
			super.getListByTypeFid2(typeid, 2, "objs2", rows, f);//
			super.getListByTypeFid2(typeid, 3, "objs3", rows, f);//
			super.getListByTypeFid2(typeid, 4, "objs4", rows, f);//
			where += " and typeid in(select id from t_type where fid="+typeid+") ";
		} else {
			super.getListByTypeid(typeid, "objs", rows, f);//
			super.getListByTypeid2(typeid, 0, "objs0", rows, f);//
			super.getListByTypeid2(typeid, 1, "objs1", rows, f);//
			super.getListByTypeid2(typeid, 2, "objs2", rows, f);//
			super.getListByTypeid2(typeid, 3, "objs3", rows, f);//
			super.getListByTypeid2(typeid, 4, "objs4", rows, f);//
			where += " and typeid="+typeid;
		}
		if(type.getMode() == 2) {//单独网页
			TNews obj = super.getDetailByTypeid(typeid, "obj", f);
			if(obj == null) {
				f.add("ret", "您要查看的信息不存在");
				return m.findPage("tips");
			}
			return m.findPage("detail");
		}
		int typeid2 = f.getInt("sid",0,true);
		if(typeid2 != 0) {
			where += " and typeid2="+typeid2;
		}
		String sql = super.select_news + where + super.order_news;
		PageUtil pu = new PageUtil("select count(*) from t_news "+where, sql, page, pageSize);
		f.add("pager", pu.setUrl(m.getFullPath() + ".htm").setParams(f.buildQueryMap()));
		return m.findPage("/list");
	}
}
